Imports System.Data.SqlClient

Friend Class DBSession
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load(ByRef oObject As Session)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [CreateDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     Session"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        With oObject
            .DatabaseID = oData.Rows(0).Item("DatabaseID")
            .CreateDate = oData.Rows(0).Item("CreateDate")
        End With

        oData.Dispose()
    End Sub

    Public Sub Add(ByRef oObject As Session)
        Dim oNextID As New DBNextIDValue("TSSession")
        Dim lNextID As Long = oNextID.NextValue
        oObject.ID = lNextID

        Dim sSQL As String = "insert into Session ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [CreateDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.databaseID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As Session)
        Dim sSQL As String = "delete from Session"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
